package com.gugu.procedure.controller;

import com.gugu.procedure.common.Constant;
import com.gugu.procedure.common.HttpServletRequestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class BaseController {

    @Value("${system.file_path}")
    public String pathPrefix;
    @Autowired
    public HttpServletRequest request;

    @Autowired
    public HttpServletRequestUtils httpServletRequestUtils;

    public String getAccount() {
        return httpServletRequestUtils.getAccount(request);
    }

    public String getName() {
        return httpServletRequestUtils.getName(request);
    }

    public String getRole() {
        return httpServletRequestUtils.getRole(request);
    }

    public boolean checkRole(String checkRole) {
        String role = httpServletRequestUtils.getRole(request);
        // 管理员特殊处理 超级管理员有管理员的所有权限
        if (Constant.MANAGER_ROLE.equals(checkRole)) {
            if (role.equals(checkRole) || Constant.SUPER_MANAGER_ROLE.equals(role)) {
                return true;
            }
        }
        return role.equals(checkRole);
    }
}
